package practise;

import java.util.Scanner;

public class Main {
    //将i定义为静态变量，这样
    public static int i;
    static class TreeNode{
        //创建树节点
        public char val;
       
        public TreeNode left;
        public TreeNode right;

        public TreeNode(char val) {
            this.val = val;
        } 
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别`
        while (in.hasNextLine()) {
            String str = in.nextLine();
            TreeNode root = null;
            i = 0;
            TreeNode ret = createTree(str,root);
            inorder(ret);
        }
    }

    public static TreeNode createTree(String str,TreeNode root) {
        //创建一棵树
        if(str==null || str.charAt(0)=='#') {
            return null;
        }
        if(i==str.length()) {
            return null;
        }
        if(str.charAt(i) == '#') {
            return null;
        }
        if(root==null) {
            root = new TreeNode(str.charAt(i));
        }
        ++i;
        root.left=createTree(str,root.left);
        ++i;
        root.right=createTree(str,root.right);
        return root;
    }

    public static void inorder(TreeNode root) {
        //中序遍历并且打印出来 左-》根 -》右
        if(root == null) {
            return;
        }
        inorder(root.left);

        System.out.print(root.val+" ");

        inorder(root.right);
    }
}